// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   CMICore.java

package com.iphaeton.lms.course.scorm12.datamodel.cmi;

import com.iphaeton.lms.course.scorm12.DebugIndicator;
import com.iphaeton.lms.course.scorm12.datamodel.Element;
import java.io.PrintStream;
import java.io.Serializable;

// Referenced classes of package com.iphaeton.lms.course.scorm12.datamodel.cmi:
//            CMICategory, CMIScore, CMIRequest, DMErrorManager

public class CMICore extends CMICategory
    implements Serializable
{

    public CMICore()
    {
        super(true);
        student_id = new Element("", "checkIdentifier", "NULL", false, true, true);
        student_name = new Element("", "checkString255", "NULL", false, true, true);
        lesson_location = new Element("", "checkString255", "NULL", true, true, true);
        credit = new Element("", "checkVocabulary", "Credit", false, true, true);
        lesson_status = new Element("", "checkVocabulary", "Status", true, true, true);
        entry = new Element("", "checkVocabulary", "Entry", false, true, true);
        total_time = new Element("", "checkTimespan", "NULL", false, true, true);
        lesson_mode = new Element("", "checkVocabulary", "Mode", false, true, true);
        exit = new Element("", "checkVocabulary", "Exit", true, false, true);
        session_time = new Element("", "checkTimespan", "NULL", true, false, true);
        score = new CMIScore();
    }

    public Element getCredit()
    {
        return credit;
    }

    public Element getEntry()
    {
        return entry;
    }

    public Element getExit()
    {
        return exit;
    }

    public Element getLessonLocation()
    {
        return lesson_location;
    }

    public Element getLessonMode()
    {
        return lesson_mode;
    }

    public Element getLessonStatus()
    {
        return lesson_status;
    }

    public CMIScore getScore()
    {
        return score;
    }

    public Element getSessionTime()
    {
        return session_time;
    }

    public Element getStudentId()
    {
        return student_id;
    }

    public Element getStudentName()
    {
        return student_name;
    }

    public Element getTotalTime()
    {
        return total_time;
    }

    public void setCredit(String inCredit)
    {
        credit.setValue(inCredit);
    }

    public void setEntry(String inEntry)
    {
        entry.setValue(inEntry);
    }

    public void setExit(String inExit)
    {
        exit.setValue(inExit);
    }

    public void setLessonLocation(String inLessonLocation)
    {
        lesson_location.setValue(inLessonLocation);
    }

    public void setLessonMode(String inLessonMode)
    {
        lesson_mode.setValue(inLessonMode);
    }

    public void setLessonStatus(String inLessonStatus)
    {
        lesson_status.setValue(inLessonStatus);
    }

    public void setScore(CMIScore inScore)
    {
        score.getRaw().setValue(inScore.getRaw().getValue());
        score.getMin().setValue(inScore.getMin().getValue());
        score.getMax().setValue(inScore.getMax().getValue());
    }

    public void setSessionTime(String inSessionTime)
    {
        session_time.setValue(inSessionTime);
    }

    public void setStudentId(String inStudentID)
    {
        student_id.setValue(inStudentID);
    }

    public void setStudentName(String inStudentName)
    {
        student_name.setValue(inStudentName);
    }

    public void setTotalTime(String inTotalTime)
    {
        total_time.setValue(inTotalTime);
    }

    public String performGet(CMIRequest theRequest, DMErrorManager dmErrorMgr)
    {
        String result = new String("");
        if(isValidCoreRequest(theRequest))
        {
            String token = theRequest.getNextToken();
            if(theRequest.hasMoreTokensToProcess())
                result = processSubcategory(theRequest, token, dmErrorMgr);
            else
            if(theRequest.isAChildrenRequest())
                result = getChildren();
            else
                result = determineElementValue(this, token, dmErrorMgr);
        } else
        {
            if(_Debug)
            {
                System.out.println("Error - Data Model Element not implemented");
                System.out.println("Request being processed: " + theRequest.getRequest() + "\nis not a valid request for the CMI Core\n" + "Data Model Category");
            }
            dmErrorMgr.recNotImplementedError(theRequest);
        }
        theRequest.done();
        return result;
    }

    public String getChildren()
    {
        String children = "student_id,student_name,lesson_location,credit,lesson_status,entry,score,total_time,lesson_mode,exit,session_time";
        return children;
    }

    public void performSet(CMIRequest theRequest, DMErrorManager dmErrorMgr)
    {
        if(isValidCoreRequest(theRequest))
        {
            String token = theRequest.getNextToken();
            String result;
            if(theRequest.hasMoreTokensToProcess())
            {
                result = processSubcategory(theRequest, token, dmErrorMgr);
            } else
            {
                String value = theRequest.getValue();
                if(theRequest.isAKeywordRequest())
                    dmErrorMgr.recKeyWordError(token);
                else
                if(token.equals("lesson_status"))
                {
                    if(value.equals("not attempted"))
                        dmErrorMgr.SetCurrentErrorCode("405");
                    else
                        doSet(this, token, value, dmErrorMgr);
                } else
                {
                    doSet(this, token, value, dmErrorMgr);
                }
            }
        } else
        {
            if(_Debug)
            {
                System.out.println("Error - Data Model Element not implemented");
                System.out.println("Request being processed: " + theRequest.getRequest() + "\nis not a valid request for the CMI Core\n" + "Data Model Category");
            }
            dmErrorMgr.recNotImplementedError(theRequest);
        }
        theRequest.done();
    }

    private String processSubcategory(CMIRequest theRequest, String theElement, DMErrorManager dmErrorMgr)
    {
        String result = new String("");
        try
        {
            java.lang.reflect.Field tmpField = getClass().getField(theElement);
            if(theRequest.isForASetRequest())
            {
                if(theRequest.isAKeywordRequest())
                    dmErrorMgr.recKeyWordError(theRequest.getElement());
                else
                    score.performSet(theRequest, dmErrorMgr);
            } else
            if(theElement.equals("score"))
                result = score.performGet(theRequest, dmErrorMgr);
            else
                dmErrorMgr.recGetKeyWordError(theRequest.getElement());
        }
        catch(NoSuchFieldException nsfe)
        {
            if(_Debug)
            {
                System.out.println("Error - Data Model Element not implemented");
                System.out.println("Element being processed: " + theElement + "is not a valid sub category of the CMI Core\n" + "Data Model Category");
            }
            dmErrorMgr.SetCurrentErrorCode("401");
        }
        catch(SecurityException se)
        {
            if(_Debug)
            {
                System.out.println(se);
                System.out.println("Access to the information is denied");
            }
            dmErrorMgr.SetCurrentErrorCode("101");
        }
        return result;
    }

    private boolean isValidCoreRequest(CMIRequest theRequest)
    {
        boolean rtrnFlag = false;
        if(theRequest.getTotalNumTokens() >= CMICORE_MIN_NUM_TOKENS)
            rtrnFlag = true;
        return rtrnFlag;
    }

    public void showData()
    {
        if(_Debug)
        {
            System.out.println("CMI Core Object:");
            System.out.println("\tstudent_id: " + getStudentId().getValue());
            System.out.println("\tstudent_name: " + getStudentName().getValue());
            System.out.println("\tlesson_location: " + getLessonLocation().getValue());
            System.out.println("\tcredit: " + getCredit().getValue());
            System.out.println("\tslesson_status: " + getLessonStatus().getValue());
            System.out.println("\tentry: " + getEntry().getValue());
            System.out.println("\texit: " + getExit().getValue());
            System.out.println("\tscore.raw: " + getScore().getRaw().getValue());
            System.out.println("\tscore.min: " + getScore().getMin().getValue());
            System.out.println("\tscore.max: " + getScore().getMax().getValue());
            System.out.println("\tsession_time: " + getSessionTime().getValue());
            System.out.println("\ttotal_time: " + getTotalTime().getValue());
            System.out.println("\tlesson_mode: " + getLessonMode().getValue());
        }
    }

    private static final long serialVersionUID = 0x47e1feccfcc1ac0cL;
    private static boolean _Debug;
    public Element credit;
    public Element entry;
    public Element exit;
    public Element lesson_location;
    public Element lesson_mode;
    public Element lesson_status;
    public CMIScore score;
    public Element session_time;
    public Element student_id;
    public Element student_name;
    public Element total_time;
    static int CMICORE_MIN_NUM_TOKENS = 3;

    static 
    {
        _Debug = DebugIndicator.ON;
    }
}
